package com.myprojects.common.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

public class User implements Serializable {
    private Integer id;

    @NotBlank(message = "用户名不能为空!")
    @Pattern(regexp = "^([A-Za-z0-9_-]){5,20}$",
            message = "用户名必须为5-20位的英文字符或数字!")
    private String username;

    @NotBlank(message = "昵称不能为空!")
    @Pattern(regexp = "^([^\"]){4,10}$",
            message = "昵称必须为4-10的任意字符!")
    private String nickname;

    @NotBlank(message = "密码不能为空!")
    @Pattern(regexp = "^[A-Za-z0-9]{5,20}$",
            message = "密码必须为5-20位的英文字符或数字!")
    private String password;

    //这个不是前端传过来的，所以不用验证
    @JsonIgnore
    private String encrypt_password;

    @NotBlank(message = "邮箱不能为空!")
    @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$",
            message = "邮箱格式错误!")
    private String email;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username == null ? null : username.trim();
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname == null ? null : nickname.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEncrypt_password() {
        return encrypt_password;
    }

    public void setEncrypt_password(String encrypt_password) {
        this.encrypt_password = encrypt_password == null ? null : encrypt_password.trim();
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", nickname='" + nickname + '\'' +
                ", password='" + password + '\'' +
                ", encrypt_password='" + encrypt_password + '\'' +
                ", email='" + email + '\'' +
                '}';
    }
}